<!--strhandleClick
 * @FileDescription 首页
 * @Author lz
 * @Date 20230117 15:03:05
 * @LastEditors lz
 * @LastEditTime 20230117 15:03:05
-->
<template>
    <!-- <div @click="strhandleClick('register')">首页</div> -->
    <div class="wp">
        <!-- 顶部 -->
        <hdrModel Hierarchy="3" :ID="0"></hdrModel>
        <div class="title">模式选择</div>
        <div class="b_img"></div>
        <div class="modular Box_j">
            <div class="classificationBox" @click="strhandleClick('MenuIndex', 0, '0')">
                <!-- <img src="/structure/jgrz.png" class="classBox_img"> -->
                结构认知教学
            </div>
            <div class="classificationBox" @click="handleClick('appraisalSettings', '拆装', '0')">
                <!-- <img src="/structure/llxl.png" class="classBox_img"> -->
                结构拆装教学
            </div>
        </div>
        <div class="modular Box_x">
            <div class="classificationBox" @click="strhandleClick('strAppraisalSettings', 1, '1')">
                <!-- <img src="/structure/fzxl.png" class="classBox_img"> -->
                结构认知训练
            </div>
            <div class="classificationBox" @click="handleClick('appraisalSettings', '拆装', '1')">
                <!-- <img src="/structure/llxl.png" class="classBox_img"> -->
                结构拆装训练
            </div>
        </div>
        <div class="modular Box_k">
            <div class="classificationBox" @click="strhandleClick('strAppraisalSettings', 2, '2')">
                <!-- <img src="/structure/fzkh.png" class="classBox_img"> -->
                结构认知考核
            </div>
            <div class="classificationBox" @click="handleClick('appraisalSettings', '拆装', '2')">
                <!-- <img src="/structure/llkh.png" class="classBox_img"> -->
                结构拆装考核
            </div>
        </div>
    </div>
</template>

<script setup lang="ts">

import hdrModel from './strHeader/index.vue'


import SplashComponent from '@components/Splash/SplashComponent';
import WebSocketComponent from '@runtime/module/WebSocket/WebSocketComponent';
import WebWindowComponent from '@runtime/module/WebWindow/WebWindowComponent';
import AssetLoaderComponent from '@runtime/UnityEngineBridge/AssetLoaderComponent';
import LabelComponent from '@runtime/UnityEngineBridge/LabelComponent';
import { onMounted, ref, nextTick, reactive } from 'vue';
import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import { useRouter } from 'vue-router'
import OrbitCameraComponent from '../InertialNavigation/OrbitCameraComponent';
import HomeContent from './HomeContent';
import AnimatorComponent from '@runtime/UnityEngineBridge/AnimatorComponent';
import TimerComponent from '@runtime/module/Timer/TimerComponent';
import appraisalData from './strAppraisalSettings/strAppraisalSettings';
import MessageCode from './MessageCode';
import AppraisalData from './appraisalSettings/appraisalSettings';
import MenuIndexData from './menu/MenuIndex';
import { installContentResponse } from './installMenu/installMenu';
const router = useRouter()

const handle = (name: string) => router.push({ name })
let Id: number = 0

function loadFile(name: any) {
  // name为文件所在位置
  let xhr = new XMLHttpRequest();
  const okStatus = document.location.protocol === "file:" ? 0 : 200;
  xhr.open("GET", name, false);
  xhr.overrideMimeType("text/html;charset=utf-8"); //默认为utf-8
  xhr.send(null);
  return xhr.status === okStatus ? xhr.responseText : null;
}

async function strhandleClick(name: string, index: Number, types: string) {
    if (types == '0') {
        HomeContent.Default.itemType.value = '教学'
    } else if (types == '1') {
        HomeContent.Default.itemType.value = '训练'
    } else if (types == '2') {
        HomeContent.Default.itemType.value = '考核'
    }
    let aaa = loadFile("./project.config.txt");
    console.log("aaaaaaaaaaaaaaa", aaa);
    await HomeContent.Default.StrAwake(aaa)
    setTimeout(async () => {
        HomeContent.Default.ProgressText.value = '数据模块初始化'
        HomeContent.Default.ProgressVal.value = 40
    }, 2000);
    if (name == 'MenuIndex') {
        HomeContent.Default.TypeStatus.value = true
        // 获取结构数据
        
        const resData: ClientMessage.StructureAdapterResponse = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.StructureAdapterRequest(MessageCode.Default.MsgCodesList.STRUCTURE_GET_TREE_MENU))        
        console.log(resData, '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++'); 
        const newData = JSON.parse(resData.Content)
        console.log(newData.Result);
        MenuIndexData.Default.MultimeterData.value = newData.Result
    }
    if (name == 'strAppraisalSettings') {
        if (index == 1) {
            console.log('训练');
            HomeContent.Default.TypeStatus.value = true
            HomeContent.Default.ApplicationType.value = '训练'

        } else if (index == 2) {
            console.log('考核');
            HomeContent.Default.TypeStatus.value = true
            HomeContent.Default.ApplicationType.value = '考核'
        }
        // 获取任务数据
        const resData: ClientMessage.StructureAdapterResponse = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.StructureAdapterRequest(MessageCode.Default.MsgCodesList.STRUCTURE_GET_ALL_TASK))
        console.log(resData, '+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++');
        const newData = JSON.parse(resData.Content)
        console.log(newData.Result);
        appraisalData.Default.AppraisalDataList.value = newData.Result._v
    }
    setTimeout(async () => {
        HomeContent.Default.ProgressText.value = '后处理模块初始化'
        HomeContent.Default.ProgressVal.value = 25
    }, 2800);
    // 隐藏背景色
    WebWindowComponent.Default.SetTransparentBackground();

    setTimeout(async () => {
        HomeContent.Default.ProgressText.value = '产品初始化'
        HomeContent.Default.ProgressVal.value = 0
    }, 3600);
    setTimeout(async () => {
        HomeContent.Default.Loaded.value = false;
    }, 4000);

    await router.push({ name })

    console.log(HomeContent.Default.TypeStatus.value);
}
async function handleClick(name: string, index: string, types: string) {

    HomeContent.Default.ApplicationType.value = index

    let aaa = loadFile("./project.config.txt");
    console.log("aaaaaaaaaaaaaaa", aaa);

    await HomeContent.Default.Awake(aaa)

    if (HomeContent.Default.ApplicationType.value == '标定') {
        //获取菜单数据
        let newArr: installContentResponse = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.CalibrationAdapterRequest(MessageCode.Default.MsgCodesList.CALIBRATION_PROJECT_GET))
        console.log(JSON.parse(newArr.Content));
        AppraisalData.Default.AppraisalDataList.value = JSON.parse(newArr.Content).Result
    } else if (HomeContent.Default.ApplicationType.value == '拆装') {
        //获取菜单数据（获取拆装项目数据）
        // let newArr: installContentResponse = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.DisassemblyAdapterRequest(MessageCode.Default.MsgCodesList.DISASSEMBLY_PROJECT_GET))
        let newArr: installContentResponse = await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.SystemAdapterRequest(MessageCode.Default.MsgCodesList.DISASSEMBLY_PROJECT_GET))
        console.log(JSON.parse(newArr.Content));
        AppraisalData.Default.AppraisalDataList.value = JSON.parse(newArr.Content).Result
    }

    setTimeout(async () => {
        HomeContent.Default.ProgressText.value = '数据模块初始化'
        HomeContent.Default.ProgressVal.value = 40
    }, 1500);
    if (HomeContent.Default.ApplicationType.value == '标定') {
        //系统初始化
        await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.CalibrationAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_INITIALIZE))
    } else if (HomeContent.Default.ApplicationType.value == '拆装') {
        //系统初始化
        // await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.DisassemblyAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_INITIALIZE))
        await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.SystemAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_INITIALIZE))
    }

    //是否可以返回
    HomeContent.Default.TypeStatus.value = true
    setTimeout(async () => {
        HomeContent.Default.ProgressText.value = '后处理模块初始化'
        HomeContent.Default.ProgressVal.value = 25
    }, 2000);

    if (HomeContent.Default.ApplicationType.value == '标定') {
        //发送类型
        await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.CalibrationAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_SET_MODE, types))
    } else if (HomeContent.Default.ApplicationType.value == '拆装') {
        //发送类型（系统模式设置）
        // await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.DisassemblyAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_SET_MODE, types))
        await WebSocketComponent.Default.PostMessageAsync(new ClientMessage.SystemAdapterRequest(MessageCode.Default.MsgCodesList.SYSTEM_SET_MODE, types))
    }
    if (types == '0') {
        HomeContent.Default.itemType.value = '教学'
    } else if (types == '1') {
        HomeContent.Default.itemType.value = '训练'
    } else if (types == '2') {
        HomeContent.Default.itemType.value = '考核'
    }
    setTimeout(async () => {
        HomeContent.Default.ProgressText.value = '产品初始化'
        HomeContent.Default.ProgressVal.value = 0
    }, 2600);
    setTimeout(async () => {
        HomeContent.Default.Loaded.value = false;
    }, 3000);
    await router.push({ name })
}
onMounted(function () {
    SplashComponent.Default.InitializeAsync()
});

</script>

<style scoped>
.wp {
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    background-image: url('/structure/bg.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.title {
    position: absolute;
    top: 128px;
    left: 835px;
    text-align: center;
    font-size: 66px;
    font-family: PangMenZhengDao;
    font-weight: 400;
    color: #FFFFFF;
}

.modular {
    padding-top: 19px;
    position: absolute;
    width: 386px;
    height: 628px;
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.Box_j {
    top: 324px;
    left: 300px;
    background-image: url('/structure/j.png');
}

.Box_x {
    top: 324px;
    left: 767px;
    background-image: url('/structure/x.png');
}

.Box_k {
    top: 324px;
    right: 300px;
    background-image: url('/structure/k.png');
}

.b_img {
    position: absolute;
    width: 1296px;
    height: 225px;
    bottom: 41px;
    right: 309px;
    background-image: url('/structure/bg_b.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
}

.classificationBox {
    margin: 20px auto;
    width: 227px;
    height: 77px;
    line-height: 77px;
    text-align: right;
    padding-right: 19px;
    font-size: 32px;
    font-family: PangMenZhengDao;
    font-weight: 400;
    color: #FFFFFF;
    background-image: url('/structure/bg_btn.png');
    background-repeat: no-repeat;
    background-size: 100% 100%;
    position: relative;
    transition: background-image .3s;
}

.classificationBox:hover {
    background-image: url('/structure/bg_btn_sel.png');
}

.classBox_img {
    position: absolute;
    left: 16px;
    top: 10px;
    width: 53px;
    height: 55px;
}

.JumpButton {
    position: absolute;
    top: 80px;
    right: 80px;
    width: 220px;
    height: 59px;
    line-height: 56px;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    color: #FFFFFF;
    border: 1px solid #FFFFFF;
    background-color: #2A415C;
    border-radius: 29px;
}
</style>